package phoenix.mob_android.test_objects;

import java.util.HashMap;
import java.util.Map;

import phoenix.core.PhoenixManager;
import phoenix.core.base.extensions.TestBaseMobAndroidExt;
import phoenix.mob_android.test_objects.data_providers.ChatDataProviders;

public class CommunicationTests extends TestBaseMobAndroidExt
{
	public CommunicationTests(PhoenixManager p_phoenix)
	{
		super(p_phoenix);
	}

	// Data
	public ChatDataProviders dataProviders = new ChatDataProviders(manager);

	public void chatroomsTest(String p_message, int p_chatNum)
	{
		try
		{
			page().mainMenu().openMainMenu().openChatRooms();
			page().chatPage().isOnChatPage().openChatrooms().chooseChatRoom(p_chatNum);

			Map<Integer, String[]> chatData = new HashMap<Integer, String[]>();
			chatData = page().chatPage().sendMessageToChatRoom(p_message);

			for (Map.Entry<Integer, String[]> entry : chatData.entrySet())
			{
				String data[] = entry.getValue();

				manager.test().assertEquals(data[0], manager.testUser().getScreenname(),
						"Screenname doesn't equals : get screenname => " + data[0] + " :actual screenname => " + manager.testUser().getScreenname());
				manager.test().assertEquals(data[1], p_message,
						"Text of the message doesn't equals : get text => " + data[1] + " :actual text => " + p_message);
			}

			page().chatPage().openRightMenu().checkForRightMenuOpened();
			page().indexPage().clickBackAndroidButton();
			page().indexPage().clickBackAndroidButton();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Chat page errors" + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}

	public void redirectPPTwoChatMessagesTest(String p_message)
	{
		try
		{
			page().mainMenu().openMainMenu().openSearch();
			page().searchPage().openPrivateChat();
			page().chatPage().sendTwoMessagesToPrivateChat(p_message);
			page().paymentPage().isOnPaymentPage();
		}
		catch (Exception p_ex)
		{
			log().errorAndScreen("Redirect to PP two chat messages test errors: " + p_ex.toString());
		}

		// Verifying result
		test().forErrors();
	}
}
